<template>
  <el-table
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    border
    style="width: 100%;margin-top: 15px"
    @selection-change="handleSelectionChange"
  >
    <el-table-column
      :selectable="({isFinished})=>isFinished !== 'Y'"
      type="selection"
      width="55"
    />
    <el-table-column
      label="序号"
      align="center"
      type="index"
      width="50"
    />
    <el-table-column
      v-for="item in tableHeader"
      :key="item.value"
      :label="item.label"
      :prop="item.value"
      show-overflow-tooltip
    >
      <template slot-scope="{ row, column }">
        <div v-if="item.url">
          <div type="text" style="color: #33aaff;cursor: pointer;width: 100%;overflow: hidden;white-space: nowrap;text-overflow:ellipsis" @click="gotoUrl(row)">{{ row[column.property] }}</div>
          <!--          <a :href='' target="_blank" > </a>-->
        </div>
        <div v-else-if="item.value === 'ifStartAccProcess'">
          <div v-if="row.ifStartAccProcess=='0'" style="color: orange">发起中</div>
          <div v-if="row.ifStartAccProcess=='1'" style="color: #07C160">发起成功</div>
          <div v-if="row.ifStartAccProcess=='2'" style="color: #c53f3f">发起失败</div>
        </div>
        <div v-else-if="item.value==='operate'">
          <el-button class="pms-zr-button-primary pms-zr-ClosedBtn" v-if="row.ifStartAccProcess!='1'" size="small" @click="handleClick(row.prjId)">发起流程</el-button>
        </div>
        <div v-else>{{ row[column.property] }}</div>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>

import { startSubAccProcessApi } from '@/api/acceptance'
import { getQueryObject } from '@/utils'

export default {
  name: 'Table',
  inject: ['prjDetail', 'workDetail'],
  props: ['parentParams', 'tableData', 'tableHeader'],
  data() {
    return {
      type: ''
    }
  },
  created() {
    const { type } = getQueryObject()
    this.type = type
  },
  methods: {
    handleSelectionChange(val) {
      this.$emit('changeCheck', val)
    },
    handleClick(prjId) {
      startSubAccProcessApi({ prjId }).then((res) => {
          if(+res.code === 200){
              this.$message.success('发起流程成功')
          }
      }).finally(() => {
        this.$emit('changeData')
      })
    },
    gotoUrl(item) {
      if (item.ifStartAccProcess!='1'){
        this.$message.warning('验收流程未发起，请先发起验收流程')
        return
      }
      if (this.type === 'todo' && item.ifStartAccProcess === '1' && item.workItemId == null) {
        // this.$message.warning('该项目已关闭，请在综合查询查看项目详情')
        window.open(`${process.env.VUE_APP_ZHONGRUAN_URL}acceptanceIntegratedQuery?processInstId=${item.processInstId}&prjId=${item.prjId}&type=1`)
        return
      }
      if (this.type=='1') {
        window.open(`${process.env.VUE_APP_ZHONGRUAN_URL}acceptanceIntegratedQuery?processInstId=${item.processInstId}&prjId=${item.prjId}&type=1`)
      } else if (item.prjStage=='Q'){
        window.open(`${process.env.VUE_APP_ZHONGRUAN_URL}settlementManagement?workItemId=${item.workItemId}&type=done`)
      } else {
        window.open(`${process.env.VUE_APP_ZHONGRUAN_URL}acceptanceIntegratedQuery?processInstId=${item.processInstId}&prjId=${item.prjId}&type=1`)
      }
    }
  }
}
</script>
<style scoped lang='scss'>
</style>
